package com.maddox.relax.bluetooth

import android.bluetooth.BluetoothDevice
import android.graphics.Color
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.maddox.relax.R

class BluetoothListAdapter(data: MutableList<BluetoothDevice>?) :
    BaseQuickAdapter<BluetoothDevice, BaseViewHolder>(R.layout.layout_bluetooth_list_item, data) {


    override fun convert(holder: BaseViewHolder, item: BluetoothDevice) {
        if (item.name == null)
            holder.setText(R.id.deviceName, "未命名")
        else
            holder.setText(R.id.deviceName, item.name)

        holder.setText(R.id.deviceMac, item.address)
        if (item.bondState==BluetoothDevice.BOND_BONDED){
            holder.setText(R.id.deviceState, "已配对")
            holder.setTextColor(R.id.deviceState, Color.GREEN)
        }else{
            holder.setText(R.id.deviceState, "新设备")
            holder.setTextColor(R.id.deviceState, Color.BLUE)
        }
    }


}